import { Card, Form, Input, Button, Select } from 'antd'


const { Option } = Select;


const MyCard = (props) => {

    const { list, title, ongetDate } = props;

    const onFinish = (data) => {
        // 给父组件传递参数
        ongetDate(data)
     }

    return <Card title={title}>
        <Form
            onFinish={onFinish}
        >
            {/* 渲染表单 */}
            {
                list.length && list.map((item, idx) => {
                    return <Form.Item key={idx} name={item.name} >
                        {
                            item.type === 'input' ?
                                <Input placeholder={item.placeholder} /> :
                                <Select placeholder="请选择身份id">
                                    {
                                        item.option.map((val, i) => {
                                            return <Option key={i} value={val.id}>{val.name}</Option>
                                        })
                                    }
                                </Select>

                        }

                    </Form.Item>
                })
            }


            {/* 提交按钮 */}
            <Form.Item >
                <Button type="primary" htmlType="submit">
                    提交
                </Button>
            </Form.Item>
        </Form>
    </Card>
}

export default MyCard